<?php
/**
 * Created by PhpStorm.
 * User: zjx
 * Date: 2016/11/25
 * Time: 10:32
 */

namespace App\Services\Utils;
use Illuminate\Support\Facades\DB;

class Transaction
{
    /**
     * @param callable $db_processor
     * @param bool $throw_err
     * @return bool
     * @throws \Exception
     */
    public static function handle(callable $db_processor, $throw_err = false)
    {
        try{
            $result = DB::transaction($db_processor);
        } catch (\Exception $e) {
            if (config('app.debug') || $throw_err) throw $e;
            $result = false;
        }

        return $result;
    }
}